﻿Shader "CookbookShaders/RampLighting"
{
	Properties
	{
		_RampTex ("Ramp Texture", 2D) = "white" {}
		_EmissiveColor ("Emissive Color", Color) = (1, 1, 1, 1)
		_AmbientColor ("Ambient Color",Color) = (1, 1, 1, 1)
		_SliderValue ("Slider", Range(0, 10)) = 0
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		CGPROGRAM
		#pragma surface surf BasicDiffuse

		sampler2D _RampTex;
		float4 _EmissiveColor;
		float4 _AmbientColor;
		float _SliderValue;
		
		inline float4 LightingBasicDiffuse(SurfaceOutput so, fixed3 lightDir, fixed atten) {
			float difLight = max(0, dot(so.Normal, lightDir));
			float hLambert = difLight * 0.5 + 0.5;
			float3 ramp = tex2D(_RampTex, float2(hLambert, hLambert)).rbg;

			float4 col;
			col.rgb = so.Albedo * _LightColor0.rgb * ramp;
			col.a = so.Alpha;
			return col;
		}

		struct Input {
			float2 uv_MainTex;
		};

		void surf(Input IN, inout SurfaceOutput o) {
			float4 c = pow((_EmissiveColor + _AmbientColor), _SliderValue);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	}
	Fallback "Diffuse"
}